<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
    <meta content="featon inc." name="author">
    <link href="/static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/vendor/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
    <link href="/static/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="/static/vendor/skin/ftskin.css" rel="stylesheet">
    <link href="/static/vendor/datetimepicker/jquery.datetimepicker.css" rel="stylesheet">
    <title></title>
</head>

<body style="margin-bottom: 60px;">

<div class="ft-subpage-wrapper container-fluid">
    <form action="#" id="form1" method="post" name="form1">
        <div class="row">
            <div class="col-lg-12" id="form_table">
                <fieldset>
                    <legend id="titleText" style="font-weight: bold">--</legend>
                    <table cellpadding="0" cellspacing="0" class="form-table form-table-border" id="">
                        <input class="hidden" id="dy_type" name="dy_type" value="调出"/>
                        <tr>
                            <th>企业名称<span class="f_red">*</span></th>
                            <td colspan="3">
                                <input class="form-control" id="qy_name" name="qy_name"/>
                            </td>
                        </tr>
                        <tr>
                            <th>负责人<span class="f_red">*</span></th>
                            <td>
                                <input class="form-control" id="legal_man" name="legal_man" style="width:263px"/>
                            </td>
                            <th>电话<span class="f_red">*</span></th>
                            <td>
                                <input class="form-control" id="phone" name="phone" style="width:263px"/>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                启运地 <span class="f_red">*</span>
                            </th>
                            <td colspan="3">
                                <div class="input-group">
                                    <select class="form-control" id="start_dq_1_id" name="start_dq_1_id"
                                            onchange="loadStartDqSheng(this.value,'start_dq_2_id')"
                                            style="width:150px">
                                        <option value="">请选择</option>
                                    </select>
                                    <select class="form-control" id="start_dq_2_id" name="start_dq_2_id"
                                            onchange="loadStartDqSheng(this.value,'start_dq_3_id')"
                                            style="width:150px">
                                        <option value="">请选择</option>
                                    </select>
                                    <select class="form-control" id="start_dq_3_id" name="start_dq_3_id"
                                            onchange="loadStartDqSheng(this.value,'start_dq_4_id')"
                                            style="width:150px">
                                        <option value="">请选择</option>
                                    </select>
                                    <select class="form-control" id="start_dq_4_id" name="start_dq_4_id"
                                            style="width:266px">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                                <span class="cError"></span>
                            </td>
                        </tr>
                        <tr>
                            <th>目的地<span class="f_red">*</span></th>
                            <td colspan="3">
                                <div class="input-group">
                                    <select class="form-control" id="end_dq_1_id" name="end_dq_1_id" onchange="loadEndDqSheng(this.value,'end_dq_2_id')"
                                            style="width:150px">
                                        <option value="">请选择</option>
                                    </select>
                                    <select class="form-control" id="end_dq_2_id" name="end_dq_2_id" onchange="loadEndDqSheng(this.value,'end_dq_3_id')"
                                            style="width:150px">
                                        <option value="">请选择</option>
                                    </select>
                                    <select class="form-control" id="end_dq_3_id" name="end_dq_3_id" onchange="loadEndDqSheng(this.value,'end_dq_4_id');"
                                            style="width:150px">
                                        <option value="">请选择</option>
                                    </select>
                                    <select class="form-control" id="end_dq_4_id" name="end_dq_4_id" onchange="getTuZaiChangList(this.value);"
                                            style="width:266px">
                                        <option value="">请选择</option>
                                    </select>
                                </div>
                                <span class="cError"></span>
                            </td>
                        </tr>
                        <tr>
                            <th>中蜂类别<span class="f_red">*</span></th>
                            <td>
                                <div class="input-group">
                                    <select class="form-control" id="bee_type" name="bee_type">

                                    </select>
                                </div>
                            </td>
                            <th>数量<span class="f_red">*</span></th>
                            <td>
                                <input id="apply_value" name="dq_id" value="0"> 箱
                            </td>
                        </tr>
                        <tr>
                            <th>登记时间<span class="f_red">*</span></th>
                            <td>
                                <div class="input-group">
                                    <input class="form-control datetime" id="record_time" name="record_time"
                                           style="width:263px"/>
                                    <span class="input-group-btn  ft-input-group-btn ft-btn-remove">
                                        <button class="btn btn-default" type="button"><span
                                                class="fa fa-calendar"></span></button>
                                    </span>
                                </div>
                            </td>
                            <th>登记人<span class="f_red">*</span></th>
                            <td>
                                <input class="form-control" id="record_man" name="record_man" style="width:263px"/>
                            </td>
                        </tr>
                    </table>
                </fieldset>
                <div class="bottom-tools-box">
                    <button class="btn btn-info" id="save_but" type="button"><span
                            aria-hidden="true" class="glyphicon glyphicon-floppy-disk"></span> 保存
                    </button>
                    <button class="btn btn-warning" onclick="top.tab_colseOnclick();" type="button"><span
                            aria-hidden="true" class="glyphicon glyphicon-remove-circle"></span> 取消
                    </button>
                </div>

            </div>
        </div>
    </form>
</div>
<input th:id="tran_id" th:value="${tran_id}" type="hidden"/>
<script src="/static/vendor/jquery/jquery-3.3.1.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/vendor/validate/jquery.validate.min.js" type="text/javascript"></script>
<script src="/static/vendor/skin/js/ft-ui.js"></script>
<script src="/static/vendor/skin/js/jquery.c.js"></script>
<script src="/static/vendor/skin/js/java.js"></script>
<script src="/static/vendor/datetimepicker/jquery.datetimepicker.js"></script>

<script>
    var tran_id = $("#tran_id").val();
    jQuery(function ($) {
        getDictList("bee_type,bee_type");
        $('#record_time').datetimepicker({
            lang: 'ch',
            timepicker: false,
            format: 'Y-m-d'
        });

        getDictList("data_type,type");
        loadStartDqSheng(1, 'start_dq_1_id');
        loadEndDqSheng(1, 'end_dq_1_id');
        iniInfoForm();
        if (tran_id != "" && tran_id != null) {
            $("#titleText").text("修改数据");
            defaultBean = top.ajax.syncl("/tran/getTranBean/" + tran_id, "");
            if (defaultBean) {
                $("#form_table").autoFill(defaultBean);
                $('#save_but').click(UpdateObject)
            }
            w
        } else {
            $("#titleText").text("添加数据");
            $('#save_but').click(addObject)
        }
    });

    $(document).ready(function () {

    });

    function iniInfoForm() {
        let validator = $("#form1").validate({
            debug: true,
            rules: {
                qy_name: {
                    required: true
                },
                legal_man: {
                    required: true
                },
                phone: {
                    required: true
                },
                start_dq_4_name: {
                    required: true
                },
                end_dq_4_name: {
                    required: true
                },
                bee_type: {
                    required: true
                },
                apply_value: {
                    required: true
                },
                record_time: {
                    required: true
                },
                record_man: {
                    required: true
                }
            },
            messages: {
                qy_name: {
                    required: "企业不能为空！"
                },
                legal_man: {
                    required: "负责人不能为空！"
                },
                phone: {
                    required: "电话不能为空！"
                },
                start_dq_4_name: {
                    required: "启运地不能为空！"
                },
                end_dq_4_name: {
                    required: "目的地不能为空！"
                },
                bee_type: {
                    required: "中蜂类型不能为空！"
                },
                apply_value: {
                    required: "数量不能为空！"
                },
                record_time: {
                    required: "登记时间不能为空！"
                },
                record_man: {
                    required: "登记人不能为空！"
                }
            },
            errorPlacement: function (error, element) {
                error.appendTo(element.parents('td').find(".cError"));
            },
            submitHandler: function (form) {

            }
        });
    }

    var is_submit = false;

    function addObject() {
        if ($("#form1").valid()) {
            if (is_submit == false) {
                is_submit = true;
                var bean = top.ajax.getBean("com.yixun.dy.entity.YxProTransport");
                $("#form_table").autoBind(bean);
                if (top.ajax.synclBody("/tran/add", bean)) {
                    modelWindow.alert(top.CMSLang.Add_success);
                    top.getCurrentFrameObj().loadListble();
                    top.tab_colseOnclick();
                } else {
                    modelWindow.error(top.CMSLang.Add_fail);
                    is_submit = false;
                }
            }
        }
    }

    function UpdateObject() {
        if ($("#form1").valid()) {
            if (is_submit == false) {
                is_submit = true;
                var bean = top.ajax.getBean("com.yixun.entity.Breed");
                $("#form_table").autoBind(bean);
                bean.breed_id = breed_id;
                if (top.ajax.synclBody("/breed/edit", bean)) {
                    modelWindow.alert(top.CMSLang.Add_success);
                    top.getCurrentFrameObj().loadListble();
                    top.tab_colseOnclick();
                } else {
                    modelWindow.error(top.CMSLang.Add_fail);
                    is_submit = false;
                }
            }
        }
    }

    /****************************行政区划选择 使用全国树 开始***************************************/
//根据乡镇编码得到全部级别树,用于出发地的选择,初始使用登录用户所在地区做为默认,或者根据选择的养殖场/户来处理
    //加载出发地行政区划
    function loadStartDqSheng(dq_id, sel_name) {
        switch (sel_name) {
            case 'start_dq_1_id':
                $('#start_dq_2_id,#start_dq_3_id,#start_dq_4_id').html('<option value="">请选择</option>');
                break;
            case 'start_dq_2_id':
                $('#start_dq_2_id,#start_dq_3_id,#start_dq_4_id').html('<option value="">请选择</option>');
                break;
            case 'start_dq_3_id':
                $('#start_dq_3_id,#start_dq_4_id').html('<option value="">请选择</option>');
                break;
            case 'start_dq_4_id':
                $('#start_dq_4_id').html('<option value="">请选择</option>');
                break;
        }

        let dq_list = top.ajax.syncl("/diqu/getChildDiquList/" + dq_id, "");
        $('#' + sel_name).addOptions(dq_list, 'dq_id', 'dq_name');
    }

    //加载目的地行政区划,根据申报类型添黑名称限制
    function loadEndDqSheng(dq_id, sel_name) {
        switch (sel_name) {
            case 'end_dq_1_id':
                $('#end_dq_2_id,#end_dq_3_id,#end_dq_4_id').html('<option value="">请选择</option>');
                break;
            case 'end_dq_2_id':
                $('#end_dq_2_id,#end_dq_3_id,#end_dq_4_id').html('<option value="">请选择</option>');
                break;
            case 'end_dq_3_id':
                $('#end_dq_3_id,#end_dq_4_id').html('<option value="">请选择</option>');
                break;
            case 'end_dq_4_id':
                $('#end_dq_4_id').html('<option value="">请选择</option>');
                break;
        }
        let dq_list = top.ajax.syncl("/diqu/getChildDiquList/" + dq_id, "");
        $('#' + sel_name).addOptions(dq_list, 'dq_id', 'dq_name');
    }

    /****************************行政区划选择 使用全国树 结束***************************************/

</script>
</body>

</html>
